package com.lian.community.service.post;


import com.lian.community.dao.post.PostPO;
import com.lian.community.dao.user.PostDAO;
import com.lian.community.entity.post.Post;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.PropertySource;
import org.springframework.stereotype.Service;


@Service
@PropertySource(value = {"classpath:post.properties"},encoding="utf-8")
public class PostService {
    @Autowired
    PostDAO postDAO;


    public Post  getPost(int id){
        Post post = new Post();
        PostPO postPO = postDAO.selectById(id);
        if(postPO == null){
            return null;
        }
        BeanUtils.copyProperties(postPO, post);
        return post;
    }

    public void addPost(Post post, int userId){
        PostPO postPO = new PostPO();
        BeanUtils.copyProperties(post, postPO);
        postPO.setDeleted(0);
        postDAO.insert(postPO);
        int postId = postDAO.lastInsertId();
        postDAO.insertUserPost(userId, postId);
    }
}
